package my.hnb.android.view.control;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.RadioButton;

/**
 * Customer radio button dang flat button
 * my.hnb.android.view.control.FlatRadioButton
 * @author BANGHN
 */
public class FlatRadioButton extends RadioButton {

	private float mX;

	public FlatRadioButton(Context context) {
		super(context);
	}

	public FlatRadioButton(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public FlatRadioButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	@Override
	public void onDraw(Canvas canvas) {

		String text = this.getText().toString();
		Paint textPaint = new Paint();
		textPaint.setAntiAlias(true);
		// float currentWidth = textPaint.measureText(text);
		float currentHeight = textPaint.measureText("x");

		textPaint.setTextSize(this.getTextSize());
		textPaint.setTextAlign(Paint.Align.CENTER);
		textPaint.setTypeface(this.getTypeface());

		Paint paint = new Paint();
		paint.setColor(android.R.color.white);
		paint.setStyle(Style.FILL);
		Rect rect = new Rect(0, 0, this.getWidth(), this.getHeight());
		canvas.drawRect(rect, paint);
		if (isChecked()) {
			textPaint.setColor(Color.RED);
		} else {

			textPaint.setColor(Color.rgb(1, 255, 100));
		}

		float h = (this.getHeight() / 2) + currentHeight;
		canvas.drawText(text, mX, h, textPaint);

	}

	@Override
	protected void onSizeChanged(int w, int h, int ow, int oh) {
		super.onSizeChanged(w, h, ow, oh);
		mX = w * 0.5f; // remember the center of the screen
	}

}
